{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3049: DtypeWarning: Columns (16,26,27) have mixed types. Specify dtype option on import or set low_memory=False.\n",
      "  interactivity=interactivity, compiler=compiler, result=result)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*********TL_M1_ID_NOBANK_ALLORGNUM***********\n",
      "                      min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 539.857]      0.0   0.0   6.0    539  0.011132  0.080997   \n",
      "(539.857, 1078.714]   0.0   0.0   5.0    539  0.009276 -0.103199   \n",
      "(1078.714, 1617.571]  0.0   1.0   6.0    539  0.011132  0.080997   \n",
      "(1617.571, 2156.429]  1.0   1.0   9.0    539  0.016698  0.492107   \n",
      "(2156.429, 2695.286]  1.0   2.0  12.0    539  0.022263  0.785465   \n",
      "(2695.286, 3234.143]  2.0   3.0  11.0    539  0.020408  0.696558   \n",
      "(3234.143, 3773.0]    3.0  40.0  11.0    539  0.020408  0.696558   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 539.857]              0.048      0.044265  \n",
      "(539.857, 1078.714]           0.040      0.044348  \n",
      "(1078.714, 1617.571]          0.048      0.044265  \n",
      "(1617.571, 2156.429]          0.072      0.044016  \n",
      "(2156.429, 2695.286]          0.096      0.043767  \n",
      "(2695.286, 3234.143]          0.088      0.043850  \n",
      "(3234.143, 3773.0]            0.088      0.043850  \n",
      "*******IV********是0.11735763546324836\n",
      "*********TL_M1_ID_NOBANK_NEWALLNUM***********\n",
      "                      min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 539.857]      0.0   0.0   7.0    539  0.012987  0.237026   \n",
      "(539.857, 1078.714]   0.0   0.0  12.0    539  0.022263  0.785465   \n",
      "(1078.714, 1617.571]  0.0   0.0   6.0    539  0.011132  0.080997   \n",
      "(1617.571, 2156.429]  0.0   0.0  11.0    539  0.020408  0.696558   \n",
      "(2156.429, 2695.286]  0.0   1.0   8.0    539  0.014842  0.372439   \n",
      "(2695.286, 3234.143]  1.0   1.0   4.0    539  0.007421 -0.328213   \n",
      "(3234.143, 3773.0]    1.0  26.0  12.0    539  0.022263  0.785465   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 539.857]              0.056      0.044182  \n",
      "(539.857, 1078.714]           0.096      0.043767  \n",
      "(1078.714, 1617.571]          0.048      0.044265  \n",
      "(1617.571, 2156.429]          0.088      0.043850  \n",
      "(2156.429, 2695.286]          0.064      0.044099  \n",
      "(2695.286, 3234.143]          0.032      0.044432  \n",
      "(3234.143, 3773.0]            0.096      0.043767  \n",
      "*******IV********是0.12740265098374887\n",
      "*********TL_M1_CELL_NOBANK_PASSNUM***********\n",
      "**********************************warining***********************************************************\n",
      "                      min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 425.143]      0.0   0.0   5.0    425  0.011765  0.136942   \n",
      "(425.143, 849.286]    0.0   0.0  14.0    424  0.033019  1.190659   \n",
      "(849.286, 1273.429]   0.0   0.0   8.0    424  0.018868  0.616515   \n",
      "(1273.429, 1697.571]  0.0   0.0   7.0    424  0.016509  0.480583   \n",
      "(1697.571, 2121.714]  0.0   0.0   8.0    424  0.018868  0.616515   \n",
      "(2121.714, 2545.857]  0.0   1.0   7.0    424  0.016509  0.480583   \n",
      "(2545.857, 2970.0]    1.0  10.0   7.0    425  0.016471  0.478188   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 425.143]              0.040      0.034881  \n",
      "(425.143, 849.286]            0.112      0.034050  \n",
      "(849.286, 1273.429]           0.064      0.034549  \n",
      "(1273.429, 1697.571]          0.056      0.034632  \n",
      "(1697.571, 2121.714]          0.064      0.034549  \n",
      "(2121.714, 2545.857]          0.056      0.034632  \n",
      "(2545.857, 2970.0]            0.056      0.034715  \n",
      "*******IV********是0.16054383636740552\n",
      "*********IR_ALLMATCH_DAYS***********\n",
      "                        min     max   sum  total      rate       woe  \\\n",
      "Bucket                                                                 \n",
      "(0.999, 643.286]        1.0    14.0  12.0    643  0.018663  0.605360   \n",
      "(643.286, 1285.571]    14.0    43.0   9.0    642  0.014019  0.314513   \n",
      "(1285.571, 1927.857]   43.0    94.0  15.0    642  0.023364  0.834863   \n",
      "(1927.857, 2570.143]   94.0   167.0  10.0    643  0.015552  0.419874   \n",
      "(2570.143, 3212.429]  167.0   302.0   8.0    642  0.012461  0.195152   \n",
      "(3212.429, 3854.714]  303.0   578.0   9.0    642  0.014019  0.314513   \n",
      "(3854.714, 4497.0]    578.0  1644.0   4.0    643  0.006221 -0.505851   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 643.286]              0.096      0.052404  \n",
      "(643.286, 1285.571]           0.072      0.052570  \n",
      "(1285.571, 1927.857]          0.120      0.052072  \n",
      "(1927.857, 2570.143]          0.080      0.052570  \n",
      "(2570.143, 3212.429]          0.064      0.052653  \n",
      "(3212.429, 3854.714]          0.072      0.052570  \n",
      "(3854.714, 4497.0]            0.032      0.053069  \n",
      "*******IV********是0.11971220534137\n",
      "*********IR_ID_X_CELL_NOTMAT_DAYS***********\n",
      "                        min     max   sum  total      rate       woe  \\\n",
      "Bucket                                                                 \n",
      "(0.999, 514.143]        1.0    36.0   3.0    514  0.005837 -0.569998   \n",
      "(514.143, 1027.286]    36.0   110.0  10.0    513  0.019493  0.649754   \n",
      "(1027.286, 1540.429]  110.0   227.0   7.0    513  0.013645  0.287133   \n",
      "(1540.429, 2053.571]  227.0   404.0   9.0    513  0.017544  0.542407   \n",
      "(2053.571, 2566.714]  405.0   588.0  11.0    513  0.021442  0.747054   \n",
      "(2566.714, 3079.857]  589.0   846.0  11.0    513  0.021442  0.747054   \n",
      "(3079.857, 3593.0]    847.0  1666.0   5.0    514  0.009728 -0.055251   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 514.143]              0.024      0.042438  \n",
      "(514.143, 1027.286]           0.080      0.041774  \n",
      "(1027.286, 1540.429]          0.056      0.042023  \n",
      "(1540.429, 2053.571]          0.072      0.041857  \n",
      "(2053.571, 2566.714]          0.088      0.041691  \n",
      "(2566.714, 3079.857]          0.088      0.041691  \n",
      "(3079.857, 3593.0]            0.040      0.042272  \n",
      "*******IV********是0.1250267438698307\n",
      "*********IR_ID_X_CELL_LASTCHG_DAYS***********\n",
      "**********************************warining***********************************************************\n",
      "**********************************warining***********************************************************\n",
      "                        min     max   sum  total      rate       woe  \\\n",
      "Bucket                                                                 \n",
      "(0.999, 235.286]        1.0    36.0   4.0    235  0.017021  0.511636   \n",
      "(235.286, 469.571]     36.0    97.0  10.0    234  0.042735  1.458698   \n",
      "(469.571, 703.857]     97.0   171.0   6.0    234  0.025641  0.930173   \n",
      "(703.857, 938.143]    172.0   285.0   4.0    235  0.017021  0.511636   \n",
      "(938.143, 1172.429]   287.0   411.0   6.0    234  0.025641  0.930173   \n",
      "(1172.429, 1406.714]  412.0   564.0   3.0    234  0.012821  0.223954   \n",
      "(1406.714, 1641.0]    565.0  1660.0   9.0    235  0.038298  1.344449   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 235.286]              0.032      0.019184  \n",
      "(235.286, 469.571]            0.080      0.018603  \n",
      "(469.571, 703.857]            0.048      0.018935  \n",
      "(703.857, 938.143]            0.032      0.019184  \n",
      "(938.143, 1172.429]           0.048      0.018935  \n",
      "(1172.429, 1406.714]          0.024      0.019184  \n",
      "(1406.714, 1641.0]            0.072      0.018769  \n",
      "*******IV********是0.2293882235636106\n",
      "*********IR_ID_X_MAIL_CNT***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 1001.143]     0.0  0.0   8.0   1001  0.007992 -0.253530   \n",
      "(1001.143, 2001.286]  0.0  0.0  17.0   1000  0.017000  0.510363   \n",
      "(2001.286, 3001.429]  0.0  0.0  11.0   1000  0.011000  0.068960   \n",
      "(3001.429, 4001.571]  0.0  0.0  10.0   1000  0.010000 -0.027361   \n",
      "(4001.571, 5001.714]  0.0  0.0  13.0   1000  0.013000  0.238038   \n",
      "(5001.714, 6001.857]  0.0  1.0  12.0   1000  0.012000  0.156983   \n",
      "(6001.857, 7002.0]    1.0  6.0  20.0   1001  0.019980  0.674919   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1001.143]             0.064      0.082468  \n",
      "(1001.143, 2001.286]          0.136      0.081638  \n",
      "(2001.286, 3001.429]          0.088      0.082136  \n",
      "(3001.429, 4001.571]          0.080      0.082219  \n",
      "(4001.571, 5001.714]          0.104      0.081970  \n",
      "(5001.714, 6001.857]          0.096      0.082053  \n",
      "(6001.857, 7002.0]            0.160      0.081472  \n",
      "*******IV********是0.0933255643989755\n",
      "*********IR_CELL_X_MAIL_CNT***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 1001.143]     0.0  0.0   4.0   1001  0.003996 -0.950697   \n",
      "(1001.143, 2001.286]  0.0  0.0  25.0   1000  0.025000  0.904197   \n",
      "(2001.286, 3001.429]  0.0  0.0   9.0   1000  0.009000 -0.133731   \n",
      "(3001.429, 4001.571]  0.0  0.0  16.0   1000  0.016000  0.448722   \n",
      "(4001.571, 5001.714]  0.0  0.0  13.0   1000  0.013000  0.238038   \n",
      "(5001.714, 6001.857]  0.0  1.0  15.0   1000  0.015000  0.383168   \n",
      "(6001.857, 7002.0]    1.0  4.0   9.0   1001  0.008991 -0.134739   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1001.143]             0.032      0.082800  \n",
      "(1001.143, 2001.286]          0.200      0.080973  \n",
      "(2001.286, 3001.429]          0.072      0.082302  \n",
      "(3001.429, 4001.571]          0.128      0.081721  \n",
      "(4001.571, 5001.714]          0.104      0.081970  \n",
      "(5001.714, 6001.857]          0.120      0.081804  \n",
      "(6001.857, 7002.0]            0.072      0.082385  \n",
      "*******IV********是0.19934246616049175\n",
      "*********IR_ID_X_CELL_CNT***********\n",
      "                      min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 1001.143]     0.0   1.0   4.0   1001  0.003996 -0.950697   \n",
      "(1001.143, 2001.286]  1.0   1.0  17.0   1000  0.017000  0.510363   \n",
      "(2001.286, 3001.429]  1.0   1.0   5.0   1000  0.005000 -0.725546   \n",
      "(3001.429, 4001.571]  1.0   1.0  10.0   1000  0.010000 -0.027361   \n",
      "(4001.571, 5001.714]  1.0   1.0  10.0   1000  0.010000 -0.027361   \n",
      "(5001.714, 6001.857]  1.0   2.0  18.0   1000  0.018000  0.568539   \n",
      "(6001.857, 7002.0]    2.0  10.0  27.0   1001  0.026973  0.982185   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1001.143]             0.032      0.082800  \n",
      "(1001.143, 2001.286]          0.136      0.081638  \n",
      "(2001.286, 3001.429]          0.040      0.082634  \n",
      "(3001.429, 4001.571]          0.080      0.082219  \n",
      "(4001.571, 5001.714]          0.080      0.082219  \n",
      "(5001.714, 6001.857]          0.144      0.081555  \n",
      "(6001.857, 7002.0]            0.216      0.080890  \n",
      "*******IV********是0.2753002310022308\n",
      "*********IR_M12_CELL_X_NAME_CNT***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 711.857]      0.0  0.0   5.0    711  0.007032 -0.382418   \n",
      "(711.857, 1422.714]   0.0  1.0   5.0    711  0.007032 -0.382418   \n",
      "(1422.714, 2133.571]  1.0  1.0  17.0    711  0.023910  0.858500   \n",
      "(2133.571, 2844.429]  1.0  1.0   7.0    711  0.009845 -0.043109   \n",
      "(2844.429, 3555.286]  1.0  1.0  19.0    711  0.026723  0.972612   \n",
      "(3555.286, 4266.143]  1.0  2.0   8.0    711  0.011252  0.091844   \n",
      "(4266.143, 4977.0]    2.0  4.0   7.0    711  0.009845 -0.043109   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 711.857]              0.040      0.058633  \n",
      "(711.857, 1422.714]           0.040      0.058633  \n",
      "(1422.714, 2133.571]          0.136      0.057636  \n",
      "(2133.571, 2844.429]          0.056      0.058467  \n",
      "(2844.429, 3555.286]          0.152      0.057470  \n",
      "(3555.286, 4266.143]          0.064      0.058384  \n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4266.143, 4977.0]            0.056      0.058467  \n",
      "*******IV********是0.1741955951368993\n",
      "*********IR_M12_ID_X_DEVICE_CNT***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 711.857]      0.0  0.0   3.0    711  0.004219 -0.896073   \n",
      "(711.857, 1422.714]   0.0  0.0  11.0    711  0.015471  0.414574   \n",
      "(1422.714, 2133.571]  0.0  0.0  11.0    711  0.015471  0.414574   \n",
      "(2133.571, 2844.429]  0.0  0.0   9.0    711  0.012658  0.211050   \n",
      "(2844.429, 3555.286]  0.0  0.0   9.0    711  0.012658  0.211050   \n",
      "(3555.286, 4266.143]  0.0  0.0  11.0    711  0.015471  0.414574   \n",
      "(4266.143, 4977.0]    0.0  4.0  14.0    711  0.019691  0.660031   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 711.857]              0.024      0.058799  \n",
      "(711.857, 1422.714]           0.088      0.058135  \n",
      "(1422.714, 2133.571]          0.088      0.058135  \n",
      "(2133.571, 2844.429]          0.072      0.058301  \n",
      "(2844.429, 3555.286]          0.072      0.058301  \n",
      "(3555.286, 4266.143]          0.088      0.058135  \n",
      "(4266.143, 4977.0]            0.112      0.057886  \n",
      "*******IV********是0.10982629149754475\n",
      "*********IR_M1_CELL_X_ID_CNT***********\n",
      "**********************************warining***********************************************************\n",
      "                      min  max  sum  total      rate       woe  goodattribute  \\\n",
      "Bucket                                                                          \n",
      "(0.999, 214.429]      0.0  0.0  0.0    214  0.000000      -inf          0.000   \n",
      "(214.429, 427.857]    0.0  1.0  2.0    213  0.009390 -0.090952          0.016   \n",
      "(427.857, 641.286]    1.0  1.0  3.0    214  0.014019  0.314513          0.024   \n",
      "(641.286, 854.714]    1.0  1.0  7.0    213  0.032864  1.185793          0.056   \n",
      "(854.714, 1068.143]   1.0  1.0  2.0    214  0.009346 -0.095680          0.016   \n",
      "(1068.143, 1281.571]  1.0  1.0  3.0    213  0.014085  0.319264          0.024   \n",
      "(1281.571, 1495.0]    1.0  2.0  3.0    214  0.014019  0.314513          0.024   \n",
      "\n",
      "                      badattribute  \n",
      "Bucket                              \n",
      "(0.999, 214.429]          0.017773  \n",
      "(214.429, 427.857]        0.017523  \n",
      "(427.857, 641.286]        0.017523  \n",
      "(641.286, 854.714]        0.017108  \n",
      "(854.714, 1068.143]       0.017607  \n",
      "(1068.143, 1281.571]      0.017440  \n",
      "(1281.571, 1495.0]        0.017523  \n",
      "*******IV********是inf\n",
      "*********IR_M1_ID_X_CELL_CNT***********\n",
      "                      min  max  sum  total      rate       woe  goodattribute  \\\n",
      "Bucket                                                                          \n",
      "(0.999, 214.429]      0.0  1.0  1.0    214  0.004673 -0.793533          0.008   \n",
      "(214.429, 427.857]    1.0  1.0  3.0    213  0.014085  0.319264          0.024   \n",
      "(427.857, 641.286]    1.0  1.0  5.0    214  0.023364  0.834863          0.040   \n",
      "(641.286, 854.714]    1.0  1.0  1.0    213  0.004695 -0.788827          0.008   \n",
      "(854.714, 1068.143]   1.0  1.0  4.0    214  0.018692  0.606946          0.032   \n",
      "(1068.143, 1281.571]  1.0  1.0  3.0    213  0.014085  0.319264          0.024   \n",
      "(1281.571, 1495.0]    1.0  4.0  3.0    214  0.014019  0.314513          0.024   \n",
      "\n",
      "                      badattribute  \n",
      "Bucket                              \n",
      "(0.999, 214.429]          0.017690  \n",
      "(214.429, 427.857]        0.017440  \n",
      "(427.857, 641.286]        0.017357  \n",
      "(641.286, 854.714]        0.017607  \n",
      "(854.714, 1068.143]       0.017440  \n",
      "(1068.143, 1281.571]      0.017440  \n",
      "(1281.571, 1495.0]        0.017523  \n",
      "*******IV********是0.049232675029086785\n",
      "*********IR_M12_ID_X_BIZ_WORK_CNT***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 711.857]      0.0  0.0   4.0    711  0.005626 -0.606977   \n",
      "(711.857, 1422.714]   0.0  0.0  15.0    711  0.021097  0.730460   \n",
      "(1422.714, 2133.571]  0.0  0.0   7.0    711  0.009845 -0.043109   \n",
      "(2133.571, 2844.429]  0.0  0.0  10.0    711  0.014065  0.317836   \n",
      "(2844.429, 3555.286]  0.0  0.0   8.0    711  0.011252  0.091844   \n",
      "(3555.286, 4266.143]  0.0  0.0  11.0    711  0.015471  0.414574   \n",
      "(4266.143, 4977.0]    0.0  4.0  13.0    711  0.018284  0.584489   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 711.857]              0.032      0.058716  \n",
      "(711.857, 1422.714]           0.120      0.057803  \n",
      "(1422.714, 2133.571]          0.056      0.058467  \n",
      "(2133.571, 2844.429]          0.080      0.058218  \n",
      "(2844.429, 3555.286]          0.064      0.058384  \n",
      "(3555.286, 4266.143]          0.088      0.058135  \n",
      "(4266.143, 4977.0]            0.104      0.057969  "
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:40: RuntimeWarning: divide by zero encountered in log\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "*******IV********是0.10848036036074485\n",
      "*********STAB_ADDR_NUM***********\n",
      "                      min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 1333.286]     0.0   0.0  15.0   1333  0.011253  0.091939   \n",
      "(1333.286, 2665.571]  0.0   0.0  10.0   1332  0.007508 -0.316557   \n",
      "(2665.571, 3997.857]  0.0   0.0  12.0   1332  0.009009 -0.132721   \n",
      "(3997.857, 5330.143]  0.0   0.0  11.0   1333  0.008252 -0.221247   \n",
      "(5330.143, 6662.429]  0.0   1.0  18.0   1332  0.013514  0.277300   \n",
      "(6662.429, 7994.714]  1.0   2.0   5.0   1332  0.003754 -1.013479   \n",
      "(7994.714, 9327.0]    2.0  70.0   5.0   1333  0.003751 -1.014232   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1333.286]             0.120      0.109459  \n",
      "(1333.286, 2665.571]          0.080      0.109792  \n",
      "(2665.571, 3997.857]          0.096      0.109625  \n",
      "(3997.857, 5330.143]          0.088      0.109792  \n",
      "(5330.143, 6662.429]          0.144      0.109127  \n",
      "(6662.429, 7994.714]          0.040      0.110207  \n",
      "(7994.714, 9327.0]            0.040      0.110290  \n",
      "*******IV********是0.16914308571191353\n",
      "*********STAB_AUTH_KEY_RELATION***********\n",
      "                        min    max   sum  total      rate       woe  \\\n",
      "Bucket                                                                \n",
      "(0.999, 1333.286]       0.0    0.0  11.0   1333  0.008252 -0.221247   \n",
      "(1333.286, 2665.571]    0.0    0.0  16.0   1332  0.012012  0.157996   \n",
      "(2665.571, 3997.857]    0.0    0.0   5.0   1332  0.003754 -1.013479   \n",
      "(3997.857, 5330.143]    0.0    0.0  11.0   1333  0.008252 -0.221247   \n",
      "(5330.143, 6662.429]    0.0    0.0  10.0   1332  0.007508 -0.316557   \n",
      "(6662.429, 7994.714]    0.0  100.0  10.0   1332  0.007508 -0.316557   \n",
      "(7994.714, 9327.0]    100.0  100.0  13.0   1333  0.009752 -0.052679   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1333.286]             0.088      0.109792  \n",
      "(1333.286, 2665.571]          0.128      0.109293  \n",
      "(2665.571, 3997.857]          0.040      0.110207  \n",
      "(3997.857, 5330.143]          0.088      0.109792  \n",
      "(5330.143, 6662.429]          0.080      0.109792  \n",
      "(6662.429, 7994.714]          0.080      0.109792  \n",
      "(7994.714, 9327.0]            0.104      0.109625  \n",
      "*******IV********是0.10290909689894341\n",
      "*********NETWORKTIME***********\n",
      "                     min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 1670.0]      6.0  24.0  21.0   1670  0.012575  0.204357   \n",
      "(1670.0, 3339.0]    24.0  99.0  18.0   1669  0.010785  0.048994   \n",
      "(3339.0, 5008.0]    99.0  99.0  23.0   1669  0.013781  0.297150   \n",
      "(5008.0, 6677.0]    99.0  99.0  15.0   1669  0.008987 -0.135143   \n",
      "(6677.0, 8346.0]    99.0  99.0  17.0   1668  0.010192 -0.008164   \n",
      "(8346.0, 10015.0]   99.0  99.0  10.0   1670  0.005988 -0.544229   \n",
      "(10015.0, 11684.0]  99.0  99.0  16.0   1669  0.009587 -0.069999   \n",
      "\n",
      "                    goodattribute  badattribute  \n",
      "Bucket                                           \n",
      "(0.999, 1670.0]             0.168      0.136949  \n",
      "(1670.0, 3339.0]            0.144      0.137115  \n",
      "(3339.0, 5008.0]            0.184      0.136700  \n",
      "(5008.0, 6677.0]            0.120      0.137364  \n",
      "(6677.0, 8346.0]            0.136      0.137115  \n",
      "(8346.0, 10015.0]           0.080      0.137862  \n",
      "(10015.0, 11684.0]          0.128      0.137281  \n",
      "*******IV********是0.055233890862097554\n",
      "*********NETWORKTIME_MONTH***********\n",
      "                     min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 1670.0]      6.0  24.0  18.0   1670  0.010778  0.048389   \n",
      "(1670.0, 3339.0]    24.0  24.0  24.0   1669  0.014380  0.340317   \n",
      "(3339.0, 5008.0]    24.0  24.0  16.0   1669  0.009587 -0.069999   \n",
      "(5008.0, 6677.0]    24.0  24.0  12.0   1669  0.007190 -0.360098   \n",
      "(6677.0, 8346.0]    24.0  24.0  20.0   1668  0.011990  0.156174   \n",
      "(8346.0, 10015.0]   24.0  24.0  13.0   1670  0.007784 -0.280056   \n",
      "(10015.0, 11684.0]  24.0  24.0  17.0   1669  0.010186 -0.008770   \n",
      "\n",
      "                    goodattribute  badattribute  \n",
      "Bucket                                           \n",
      "(0.999, 1670.0]             0.144      0.137198  \n",
      "(1670.0, 3339.0]            0.192      0.136617  \n",
      "(3339.0, 5008.0]            0.128      0.137281  \n",
      "(5008.0, 6677.0]            0.096      0.137613  \n",
      "(6677.0, 8346.0]            0.160      0.136866  \n",
      "(8346.0, 10015.0]           0.104      0.137613  \n",
      "(10015.0, 11684.0]          0.136      0.137198  \n",
      "*******IV********是0.04784859506682724\n",
      "*********MONETARY***********\n",
      "                        min    max   sum  total      rate       woe  \\\n",
      "Bucket                                                                \n",
      "(0.999, 1664.143]       0.0   35.0  19.0   1664  0.011418  0.106702   \n",
      "(1664.143, 3327.286]   35.0   75.0  28.0   1663  0.016837  0.500565   \n",
      "(3327.286, 4990.429]   75.0  120.0  12.0   1663  0.007216 -0.356471   \n",
      "(4990.429, 6653.571]  120.0  140.0  26.0   1663  0.015634  0.425235   \n",
      "(6653.571, 8316.714]  140.0  140.0  10.0   1663  0.006013 -0.540003   \n",
      "(8316.714, 9979.857]  140.0  160.0  12.0   1663  0.007216 -0.356471   \n",
      "(9979.857, 11643.0]   160.0  300.0  13.0   1664  0.007812 -0.276428   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1664.143]             0.152      0.136617  \n",
      "(1664.143, 3327.286]          0.224      0.135786  \n",
      "(3327.286, 4990.429]          0.096      0.137115  \n",
      "(4990.429, 6653.571]          0.208      0.135952  \n",
      "(6653.571, 8316.714]          0.080      0.137281  \n",
      "(8316.714, 9979.857]          0.096      0.137115  \n",
      "(9979.857, 11643.0]           0.104      0.137115  \n",
      "*******IV********是0.145833811424511\n",
      "*********CUSTOMER_AGE***********\n",
      "                       min   max   sum  total      rate       woe  \\\n",
      "Bucket                                                              \n",
      "(0.999, 739.857]      20.0  27.0  14.0    739  0.018945  0.620645   \n",
      "(739.857, 1478.714]   27.0  31.0  10.0    739  0.013532  0.278670   \n",
      "(1478.714, 2217.571]  31.0  35.0   6.0    739  0.008119 -0.237627   \n",
      "(2217.571, 2956.429]  35.0  39.0   4.0    739  0.005413 -0.645817   \n",
      "(2956.429, 3695.286]  39.0  44.0   5.0    739  0.006766 -0.421312   \n",
      "(3695.286, 4434.143]  44.0  49.0   9.0    739  0.012179  0.171939   \n",
      "(4434.143, 5173.0]    49.0  60.0  11.0    739  0.014885  0.375353   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 739.857]              0.112      0.060211  \n",
      "(739.857, 1478.714]           0.080      0.060543  \n",
      "(1478.714, 2217.571]          0.048      0.060875  \n",
      "(2217.571, 2956.429]          0.032      0.061041  \n",
      "(2956.429, 3695.286]          0.040      0.060958  \n",
      "(3695.286, 4434.143]          0.072      0.060626  \n",
      "(4434.143, 5173.0]            0.088      0.060460  \n",
      "*******IV********是0.08050246225348817\n",
      "*********BILLINGCHARGE***********\n",
      "                      min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                            \n",
      "(0.999, 1664.143]     1.0  2.0  27.0   1664  0.016226  0.462975   \n",
      "(1664.143, 3327.286]  2.0  4.0  35.0   1663  0.021046  0.728000   \n",
      "(3327.286, 4990.429]  4.0  5.0  12.0   1663  0.007216 -0.356471   \n",
      "(4990.429, 6653.571]  5.0  7.0   9.0   1663  0.005412 -0.645968   \n",
      "(6653.571, 8316.714]  7.0  8.0  13.0   1663  0.007817 -0.275822   \n",
      "(8316.714, 9979.857]  8.0  9.0   9.0   1663  0.005412 -0.645968   \n",
      "(9979.857, 11643.0]   9.0  9.0  15.0   1664  0.009014 -0.132115   \n",
      "\n",
      "                      goodattribute  badattribute  \n",
      "Bucket                                             \n",
      "(0.999, 1664.143]             0.216      0.135952  \n",
      "(1664.143, 3327.286]          0.280      0.135205  \n",
      "(3327.286, 4990.429]          0.096      0.137115  \n",
      "(4990.429, 6653.571]          0.072      0.137364  \n",
      "(6653.571, 8316.714]          0.104      0.137032  \n",
      "(8316.714, 9979.857]          0.072      0.137364  \n",
      "(9979.857, 11643.0]           0.120      0.136949  \n",
      "*******IV********是0.252923557283093\n",
      "*********SCORE***********\n",
      "**********************************warining***********************************************************\n",
      "                     min   max  sum  total      rate       woe  goodattribute  \\\n",
      "Bucket                                                                          \n",
      "(0.999, 166.714]     1.0  12.0  4.0    166  0.024096  0.866457          0.032   \n",
      "(166.714, 332.429]  12.0  15.0  2.0    166  0.012048  0.161040          0.016   \n",
      "(332.429, 498.143]  15.0  18.0  0.0    166  0.000000      -inf          0.000   \n",
      "(498.143, 663.857]  19.0  35.0  3.0    165  0.018182  0.578775          0.024   \n",
      "(663.857, 829.571]  35.0  44.0  5.0    166  0.030120  1.095793          0.040   \n",
      "(829.571, 995.286]  44.0  52.0  2.0    166  0.012048  0.161040          0.016   \n",
      "(995.286, 1161.0]   52.0  83.0  1.0    166  0.006024 -0.538186          0.008   \n",
      "\n",
      "                    badattribute  \n",
      "Bucket                            \n",
      "(0.999, 166.714]        0.013454  \n",
      "(166.714, 332.429]      0.013620  \n",
      "(332.429, 498.143]      0.013786  \n",
      "(498.143, 663.857]      0.013454  \n",
      "(663.857, 829.571]      0.013371  \n",
      "(829.571, 995.286]      0.013620  \n",
      "(995.286, 1161.0]       0.013703  \n",
      "*******IV********是inf\n",
      "*********ZIYINGA_SCORE***********\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:40: RuntimeWarning: divide by zero encountered in log\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\lib\\function_base.py:2530: RuntimeWarning: invalid value encountered in true_divide\n",
      "  c /= stddev[:, None]\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\numpy\\lib\\function_base.py:2531: RuntimeWarning: invalid value encountered in true_divide\n",
      "  c /= stddev[None, :]\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:877: RuntimeWarning: invalid value encountered in greater\n",
      "  return (self.a < x) & (x < self.b)\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:877: RuntimeWarning: invalid value encountered in less\n",
      "  return (self.a < x) & (x < self.b)\n",
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\scipy\\stats\\_distn_infrastructure.py:1831: RuntimeWarning: invalid value encountered in less_equal\n",
      "  cond2 = cond0 & (x <= self.a)\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                       min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 1693.714]      0.0  0.0  13.0   1693  0.007679 -0.293841   \n",
      "(1693.714, 3386.429]   0.0  0.0  30.0   1693  0.017720  0.552578   \n",
      "(3386.429, 5079.143]   0.0  0.0  14.0   1693  0.008269 -0.219137   \n",
      "(5079.143, 6771.857]   0.0  0.0  12.0   1692  0.007092 -0.373883   \n",
      "(6771.857, 8464.571]   0.0  0.0  21.0   1693  0.012404  0.190506   \n",
      "(8464.571, 10157.286]  0.0  0.0  14.0   1693  0.008269 -0.219137   \n",
      "(10157.286, 11850.0]   0.0  0.0  18.0   1693  0.010632  0.034562   \n",
      "\n",
      "                       goodattribute  badattribute  \n",
      "Bucket                                              \n",
      "(0.999, 1693.714]              0.104      0.139523  \n",
      "(1693.714, 3386.429]           0.240      0.138111  \n",
      "(3386.429, 5079.143]           0.112      0.139440  \n",
      "(5079.143, 6771.857]           0.096      0.139523  \n",
      "(6771.857, 8464.571]           0.168      0.138859  \n",
      "(8464.571, 10157.286]          0.112      0.139440  \n",
      "(10157.286, 11850.0]           0.144      0.139108  \n",
      "*******IV********是0.10075917480877415\n",
      "*********ZIYINGB_SCORE***********\n",
      "                         min    max   sum  total      rate       woe  \\\n",
      "Bucket                                                                 \n",
      "(0.999, 1693.714]        0.0  531.0  45.0   1693  0.026580  0.967104   \n",
      "(1693.714, 3386.429]   531.0  561.0  18.0   1693  0.010632  0.034562   \n",
      "(3386.429, 5079.143]   561.0  583.0  16.0   1693  0.009451 -0.084414   \n",
      "(5079.143, 6771.857]   583.0  602.0  12.0   1692  0.007092 -0.373883   \n",
      "(6771.857, 8464.571]   602.0  625.0  16.0   1693  0.009451 -0.084414   \n",
      "(8464.571, 10157.286]  625.0  653.0  11.0   1693  0.006497 -0.462085   \n",
      "(10157.286, 11850.0]   653.0  749.0   4.0   1693  0.002363 -1.477839   \n",
      "\n",
      "                       goodattribute  badattribute  \n",
      "Bucket                                              \n",
      "(0.999, 1693.714]              0.360      0.136866  \n",
      "(1693.714, 3386.429]           0.144      0.139108  \n",
      "(3386.429, 5079.143]           0.128      0.139274  \n",
      "(5079.143, 6771.857]           0.096      0.139523  \n",
      "(6771.857, 8464.571]           0.128      0.139274  \n",
      "(8464.571, 10157.286]          0.088      0.139689  \n",
      "(10157.286, 11850.0]           0.032      0.140271  \n",
      "*******IV********是0.41803067270875705\n",
      "*********EDUCATION_DEGREE***********\n",
      "                       min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 1738.857]        1    2  21.0   1738  0.012083  0.163948   \n",
      "(1738.857, 3476.714]     2    2  26.0   1738  0.014960  0.380438   \n",
      "(3476.714, 5214.571]     2    2  20.0   1738  0.011507  0.114575   \n",
      "(5214.571, 6952.429]     2    2  14.0   1738  0.008055 -0.245586   \n",
      "(6952.429, 8690.286]     2    3  14.0   1738  0.008055 -0.245586   \n",
      "(8690.286, 10428.143]    3    3  18.0   1738  0.010357  0.008051   \n",
      "(10428.143, 12166.0]     3    6  12.0   1738  0.006904 -0.400896   \n",
      "\n",
      "                       goodattribute  badattribute  \n",
      "Bucket                                              \n",
      "(0.999, 1738.857]              0.168      0.142596  \n",
      "(1738.857, 3476.714]           0.208      0.142181  \n",
      "(3476.714, 5214.571]           0.160      0.142679  \n",
      "(5214.571, 6952.429]           0.112      0.143177  \n",
      "(6952.429, 8690.286]           0.112      0.143177  \n",
      "(8690.286, 10428.143]          0.144      0.142845  \n",
      "(10428.143, 12166.0]           0.096      0.143344  \n",
      "*******IV********是0.06549220027587532\n",
      "*********MONTHLY_SALARY***********\n",
      "                       min  max   sum  total      rate       woe  \\\n",
      "Bucket                                                             \n",
      "(0.999, 1738.857]        1    2  15.0   1738  0.008631 -0.176013   \n",
      "(1738.857, 3476.714]     2    2  21.0   1738  0.012083  0.163948   \n",
      "(3476.714, 5214.571]     2    2  17.0   1738  0.009781 -0.049688   \n",
      "(5214.571, 6952.429]     2    2  12.0   1738  0.006904 -0.400896   \n",
      "(6952.429, 8690.286]     2    3  20.0   1738  0.011507  0.114575   \n",
      "(8690.286, 10428.143]    3    3  13.0   1738  0.007480 -0.320274   \n",
      "(10428.143, 12166.0]     3    4  27.0   1738  0.015535  0.418763   \n",
      "\n",
      "                       goodattribute  badattribute  \n",
      "Bucket                                              \n",
      "(0.999, 1738.857]              0.120      0.143094  \n",
      "(1738.857, 3476.714]           0.168      0.142596  \n",
      "(3476.714, 5214.571]           0.136      0.142928  \n",
      "(5214.571, 6952.429]           0.096      0.143344  \n",
      "(6952.429, 8690.286]           0.160      0.142679  \n",
      "(8690.286, 10428.143]          0.104      0.143261  \n",
      "(10428.143, 12166.0]           0.216      0.142098  \n",
      "*******IV********是0.07306006592320172\n",
      "###年龄处理######\n",
      "              总客户数  坏客户数   badrate\n",
      "CUSTOMER_AGE                      \n",
      "(55, 60]       137   4.0  0.029197\n",
      "(0, 25]        455   8.0  0.017582\n",
      "(25, 30]       913  16.0  0.017525\n",
      "(50, 55]       377   6.0  0.015915\n",
      "(45, 50]       722   8.0  0.011080\n",
      "(40, 45]       749   7.0  0.009346\n",
      "(30, 35]       960   6.0  0.006250\n",
      "(35, 40]       860   4.0  0.004651\n",
      "(60, 999]        0   0.0       NaN\n",
      "###学历处理######\n",
      "                 总客户数  坏客户数   badrate\n",
      "EDUCATIONDEGREE                      \n",
      "1.0              1500  21.0  0.014000\n",
      "2.0              6322  65.0  0.010282\n",
      "3.0              3059  31.0  0.010134\n",
      "4.0              1235   8.0  0.006478\n",
      "5.0                42   0.0  0.000000\n",
      "6.0                 8   0.0  0.000000\n",
      "###月薪处理######\n",
      "                总客户数  坏客户数   badrate\n",
      "MONTHLY_SALARY                      \n",
      "1                272   4.0  0.014706\n",
      "4                942  12.0  0.012739\n",
      "3               3929  47.0  0.011962\n",
      "2               7023  62.0  0.008828\n",
      "###分流标识处理######\n",
      "                  总客户数  坏客户数   badrate\n",
      "RULE_FLOW_REMARK                      \n",
      "A                 4523  51.0  0.011276\n",
      "B                 6993  70.0  0.010010\n",
      "测试备注               334   1.0  0.002994\n",
      "###银行处理######\n",
      "                  总客户数  坏客户数   badrate\n",
      "DEBIT_BANK_NAME                       \n",
      "云南省农村信用社             1   1.0  1.000000\n",
      "中银富登村镇银行             5   1.0  0.200000\n",
      "邮政储蓄银行              57   3.0  0.052632\n",
      "平安银行               152   3.0  0.019737\n",
      "中国邮政储蓄银行           747  14.0  0.018742\n",
      "民生银行                66   1.0  0.015152\n",
      "中信银行                68   1.0  0.014706\n",
      "工商银行              1244  18.0  0.014469\n",
      "邮储银行               457   6.0  0.013129\n",
      "重庆农村商业银行           332   4.0  0.012048\n",
      "建设银行              2177  26.0  0.011943\n",
      "中国农业银行            1099  13.0  0.011829\n",
      "招商银行               366   4.0  0.010929\n",
      "广发银行                95   1.0  0.010526\n",
      "中国工商银行             711   6.0  0.008439\n",
      "交通银行               248   2.0  0.008065\n",
      "农业银行              1833  14.0  0.007638\n",
      "江苏省农村信用社           162   1.0  0.006173\n",
      "中国银行              1064   6.0  0.005639\n",
      "江阴农商银行              62   0.0  0.000000\n",
      "江苏江南农村商业银行           2   0.0  0.000000\n",
      "江南农村商业银行             3   0.0  0.000000\n",
      "昆山农商行                1   0.0  0.000000\n",
      "无锡农村商业银行            48   0.0  0.000000\n",
      "江苏江阴农村商业银行          64   0.0  0.000000\n",
      "新疆农信                 1   0.0  0.000000\n",
      "江苏省农村信用社联合社        277   0.0  0.000000\n",
      "恒丰银行                 3   0.0  0.000000\n",
      "江苏银行               110   0.0  0.000000\n",
      "江西农信                 1   0.0  0.000000\n",
      "...                ...   ...       ...\n",
      "东莞农村商业银行           109   0.0  0.000000\n",
      "东莞农商银行             100   0.0  0.000000\n",
      "上海银行                 1   0.0  0.000000\n",
      "ICBC_D_QB2C-4103     1   0.0  0.000000\n",
      "华夏银行                29   0.0  0.000000\n",
      "ICBC_D_QB2C-1897     1   0.0  0.000000\n",
      "CMB_D_QB2C-7805      1   0.0  0.000000\n",
      "CCB_D_QB2C-4878      1   0.0  0.000000\n",
      "CCB_D_QB2C-3326      1   0.0  0.000000\n",
      "CCB_D_QB2C-2844      1   0.0  0.000000\n",
      "CCB_D_QB2C-2725      1   0.0  0.000000\n",
      "兴业银行                54   0.0  0.000000\n",
      "南京银行                15   0.0  0.000000\n",
      "广西农村信用社              3   0.0  0.000000\n",
      "广东发展银行               2   0.0  0.000000\n",
      "广西农信银行               2   0.0  0.000000\n",
      "广州农村商业银行股份有限公司       1   0.0  0.000000\n",
      "广州农商银行               1   0.0  0.000000\n",
      "BOC_D_QB2C-9370      1   0.0  0.000000\n",
      "广东顺德农村商业银行           1   0.0  0.000000\n",
      "广东省农村信用社联合社         70   0.0  0.000000\n",
      "广东农信                56   0.0  0.000000\n",
      "南粤银行                 1   0.0  0.000000\n",
      "平安银行股份有限公司           1   0.0  0.000000\n",
      "常熟农商银行               2   0.0  0.000000\n",
      "安徽农信社                1   0.0  0.000000\n",
      "安徽农信                 1   0.0  0.000000\n",
      "宁波银行                 8   0.0  0.000000\n",
      "四川农信                 3   0.0  0.000000\n",
      "黑龙江农村信用社             1   0.0  0.000000\n",
      "\n",
      "[84 rows x 3 columns]\n",
      "###二手单处理######\n",
      "      总客户数  坏客户数   badrate\n",
      "二手单                       \n",
      "1.0   1722  38.0  0.022067\n",
      "0.0  10444  87.0  0.008330\n",
      "###行业处理######\n",
      "                   总客户数  坏客户数   badrate\n",
      "INDUSTRY_CATEGORY                      \n",
      "11.0                231   6.0  0.025974\n",
      "5.0                 597  13.0  0.021776\n",
      "18.0                 96   2.0  0.020833\n",
      "16.0                477   7.0  0.014675\n",
      "7.0                 598   8.0  0.013378\n",
      "8.0                1055  14.0  0.013270\n",
      "17.0                301   3.0  0.009967\n",
      "9.0                 514   5.0  0.009728\n",
      "6.0                2590  25.0  0.009653\n",
      "3.0                3889  35.0  0.009000\n",
      "1.0                 558   4.0  0.007168\n",
      "15.0                286   2.0  0.006993\n",
      "10.0                241   1.0  0.004149\n",
      "12.0                 95   0.0  0.000000\n",
      "13.0                 40   0.0  0.000000\n",
      "14.0                 70   0.0  0.000000\n",
      "2.0                  44   0.0  0.000000\n",
      "4.0                 390   0.0  0.000000\n",
      "19.0                 90   0.0  0.000000\n",
      "20.0                  3   0.0  0.000000\n",
      "###紧急联系人1处理######\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                              总客户数  坏客户数   badrate\n",
      "EMERGANCY_FIRST_RELATIONSHIP                      \n",
      "0.0                           1717  26.0  0.015143\n",
      "2.0                            732   8.0  0.010929\n",
      "3.0                           3064  33.0  0.010770\n",
      "1.0                           6652  58.0  0.008719\n",
      "6.0                              1   0.0  0.000000\n",
      "###紧急联系人2处理######\n",
      "                                总客户数  坏客户数   badrate\n",
      "EMERGANCY_SECOND_RELATIONSHIP                       \n",
      "5.0                              336   5.0  0.014881\n",
      "4.0                             1755  22.0  0.012536\n",
      "6.0                            10075  98.0  0.009727\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import os\n",
    "os.chdir('D:\\百融')\n",
    "df=pd.read_csv('去重百融.csv')\n",
    "#定义逾期转换函数\n",
    "def trans(x):\n",
    "    x=str(x)\n",
    "    if x =='CLOSE':\n",
    "        return 0\n",
    "    elif x == 'OPEN':\n",
    "        return 1\n",
    "    elif x == 'CLEAR':\n",
    "        return 0\n",
    "    elif x == 'TERMINATE':\n",
    "        return 0\n",
    "#逾期转换\n",
    "df['y06'] = df['STATUS3'].map(trans)\n",
    "df['y05'] = df['STATUS2'].map(trans)\n",
    "df['y04'] = df['STATUS2'].map(trans)\n",
    "#定义分箱函数\n",
    "import scipy.stats.stats as stats\n",
    "def mono_bin(Y, X, n=20):\n",
    "    r = 0\n",
    "    good = Y.sum()\n",
    "    bad = Y.count() - good\n",
    "    while np.abs(r) < 1:\n",
    "        d1 = pd.DataFrame({\"X\": X, \"Y\": Y, \"Bucket\": pd.qcut(X.rank(method=\"first\"), n)})\n",
    "        # X.rank(method=\"first\")\n",
    "        d2 = d1.groupby(\"Bucket\", as_index = True)\n",
    "        r, p = stats.spearmanr(d2.mean().X, d2.mean().Y)\n",
    "        # 使用斯皮尔曼等级相关系数来评估两个变量之间的相关性\n",
    "        n = n - 1\n",
    "        d3 = pd.DataFrame(d2.X.min(), columns = ['min'])\n",
    "        d3['min']=d2.min().X\n",
    "        d3['max'] = d2.max().X\n",
    "        d3['sum'] = d2.sum().Y\n",
    "        d3['total'] = d2.count().Y\n",
    "        d3['rate'] = d2.mean().Y\n",
    "        d3['woe'] = np.log((d3['rate'] / (1-d3['rate'])) / (good/bad))\n",
    "        d3['goodattribute'] = d3['sum'] / good\n",
    "        d3['badattribute'] = (d3['total'] - d3['sum']) / bad\n",
    "        for i in list(d3['rate']):\n",
    "            if i>0.03:\n",
    "                print('**********************************warining***********************************************************')\n",
    "        iv = ((d3['goodattribute'] - d3['badattribute']) * d3['woe']).sum()\n",
    "        d4 = (d3.sort_values(by = 'min'))\n",
    "        print(d4)\n",
    "        print('*******IV********是'+str(iv))\n",
    "        cut=[]\n",
    "        cut.append(float('-inf'))\n",
    "        ivs.append(iv)\n",
    "        for i in range(1, n+1):\n",
    "            qua = X.quantile(i/(n+1))\n",
    "            cut.append(round(qua,4))\n",
    "            cut.append(float('inf'))\n",
    "            woe = list(d4['woe'].round(3))\n",
    "            return d4, iv, cut, woe\n",
    "\n",
    "#计算IV并保存\n",
    "df2=df[(df['y06'].isin([0,1]))]\n",
    "cols=[]\n",
    "ivs=[]\n",
    "for i in [ 'TL_M1_ID_NOBANK_ALLORGNUM',\n",
    " 'TL_M1_ID_NOBANK_NEWALLNUM',\n",
    " 'TL_M1_CELL_NOBANK_PASSNUM',\n",
    " 'IR_ALLMATCH_DAYS',\n",
    " 'IR_ID_X_CELL_NOTMAT_DAYS',\n",
    " 'IR_ID_X_CELL_LASTCHG_DAYS',\n",
    " 'IR_ID_X_MAIL_CNT',\n",
    " 'IR_CELL_X_MAIL_CNT',\n",
    " 'IR_ID_X_CELL_CNT',\n",
    " 'IR_M12_CELL_X_NAME_CNT',\n",
    " 'IR_M12_ID_X_DEVICE_CNT',\n",
    " 'IR_M1_CELL_X_ID_CNT',\n",
    " 'IR_M1_ID_X_CELL_CNT',\n",
    " 'IR_M12_ID_X_BIZ_WORK_CNT',\n",
    " 'STAB_ADDR_NUM',\n",
    " 'STAB_AUTH_KEY_RELATION',\n",
    " 'NETWORKTIME',\n",
    " 'NETWORKTIME_MONTH',\n",
    " 'MONETARY',\n",
    "          'CUSTOMER_AGE',\n",
    " 'BILLINGCHARGE',\n",
    "          'SCORE',\n",
    " 'ZIYINGA_SCORE',\n",
    " 'ZIYINGB_SCORE','EDUCATION_DEGREE',\n",
    "       'MONTHLY_SALARY']:\n",
    "    print('*********'+i+'***********')\n",
    "    mono_bin(df2['y06'],df2[i],n=7)\n",
    "    cols.append(i)\n",
    "iv_matrix={'cols':cols,'iv':ivs}\n",
    "pd.DataFrame(iv_matrix).sort_values(by='iv',ascending=False).to_csv('月度IV跟踪.csv')\n",
    "\n",
    "\n",
    "\n",
    "##计算分客群badrate并保存\n",
    "print('###年龄处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['CUSTOMER_AGE']>0)]\n",
    "bins=[0,25,30,35,40,45,50,55,60,999]\n",
    "age_box=pd.cut(df1['CUSTOMER_AGE'],bins)\n",
    "age_cut_group=df1['y06'].groupby(age_box).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(age_box).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('年龄分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###学历处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['EDUCATIONDEGREE'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['EDUCATIONDEGREE']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['EDUCATIONDEGREE']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('学历分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###月薪处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['MONTHLY_SALARY'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['MONTHLY_SALARY']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['MONTHLY_SALARY']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('月薪分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###分流标识处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['RULE_FLOW_REMARK'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['RULE_FLOW_REMARK']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['RULE_FLOW_REMARK']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('分流分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###银行处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['DEBIT_BANK_NAME'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['DEBIT_BANK_NAME']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['DEBIT_BANK_NAME']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('银行分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###二手单处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['二手单'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['二手单']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['二手单']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('银行分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###行业处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['INDUSTRY_CATEGORY'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['INDUSTRY_CATEGORY']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['INDUSTRY_CATEGORY']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('行业分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###紧急联系人1处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['EMERGANCY_FIRST_RELATIONSHIP'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['EMERGANCY_FIRST_RELATIONSHIP']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['EMERGANCY_FIRST_RELATIONSHIP']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('紧急联系人1分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))\n",
    "print('###紧急联系人2处理######')\n",
    "df1=df[(df['y06'].isin([0,1]))&(df['EMERGANCY_SECOND_RELATIONSHIP'].notnull())]\n",
    "age_cut_group=df1['y06'].groupby(df1['EMERGANCY_SECOND_RELATIONSHIP']).count()\n",
    "age_cut_grouped1=df1[\"y06\"].groupby(df1['EMERGANCY_SECOND_RELATIONSHIP']).sum()\n",
    "age_bad_rate=pd.merge(pd.DataFrame(age_cut_group),pd.DataFrame(age_cut_grouped1),left_index=True,right_index=True)\n",
    "age_bad_rate.reset_index()\n",
    "age_bad_rate.rename(columns={'y06_x':'总客户数','y06_y':'坏客户数'},inplace=True)\n",
    "age_bad_rate['badrate']=age_bad_rate['坏客户数']/age_bad_rate['总客户数']\n",
    "age_bad_rate.sort_values(by='badrate',ascending=False).to_csv('紧急联系人2分布.csv',encoding='gbk')\n",
    "print(age_bad_rate.sort_values(by='badrate',ascending=False))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
